
<#-- *************** Relationship Tests *************** -->

<#-- DEPRECATED-->
<#-- has Children Evaluation  No Recurse-->
<#macro childrenLoop boName>
<#assign bo = app.getEntityByName(boName)>
<#list bo.members as member>
	<#if app.isOneToMany(bo, member)>	
		<#assign cap = member.memberNameSingular?cap_first>
		<#assign low = member.memberNameSingular?lower_case>
		<#nested cap, low>
	</#if>
</#list>
</#macro>

<#-- DEPRECATED-->
<#-- has Children Recursive Evaluation 
* 1.  Takes as parameters 
		a.  String of the current BO (boName)
		b.  String of the current Bo's parentChild (oldparentChildcombo) from Tiles backtracking
* 1.5 We instantiate the BO by name with a utility method
* 2.  Loops through all the members of the BO, looking for Entity Relationships
* 3.  If a relationships is found, we set three strings..
		a.  childname?lower_case
		b.  parentname?lower_case
		c.  parentChildName (parent and child concatonated)
		d.  oldparentname (for tiles back-tracking purposes)
* 4.  Then we pass these stings back to the nested content to display
* 5.  We need to then check if the current childname, also has Entity Children
*   We do this by calling the macro recursively and passing the nested content with it.  
-->
<#macro hasChildrenRecurse boName parentChildCombo>
<#assign bo = app.getBoByName(boName)>
<#list bo.members as member>
	<#if app.isOneToMany(bo, member)>
			<#--Assignments -->
			<#assign childname = member.memberNameSingular?cap_first>
			<#assign parentname = boName?lower_case>
			<#assign parentChildname = parentname?lower_case + childname?cap_first>
			<#assign oldparentChildCombo = parentChildCombo>
			<#--Call the Nested Text -->
		<#nested childname, parentname, parentChildname, oldparentChildCombo>
		<#--Call this function recursively -->
		<@hasChildrenRecurse childname, parentChildname>
			<#nested childname, parentname, parentChildname, oldparentChildCombo>
		</@hasChildrenRecurse>
	</#if>
</#list>
</#macro>
<#-- for tabs only-->
<#macro OTMChildrenLoopRecurse aparent>
<#list util.getOneToManyChildren(aparent) as child>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign child = child><#-- neccessary for macros -->
		<#nested>
		<@OTMChildrenLoopRecurse child>
			<#nested>
		</@OTMChildrenLoopRecurse>
		</tab>
</#list>
</#macro>


<#-- for tabs only-->
<#macro secondOTMLoopRecurse aparent history>
<#assign history = history>
<#assign aparent = aparent>
<#list util.getOneToManyChildren(aparent) as child>
	<#if history == ""> <#-- don't use the '.' on the first level -->
		<#assign inner = aparent.entityName?lower_case>		
	<#else>
		<#assign inner = history + "." + aparent.entityName?lower_case>		
	</#if>
	<#assign child = child><#-- neccessary for macros -->
		<#nested>		
		<@secondOTMLoopRecurse child, inner>
			<#nested>
		</@secondOTMLoopRecurse>
</#list>
</#macro>



<#-- *************** TESTS *************** -->
<#-- has a parent Test  -->
<#-- tests if the currnet BO has any parents -->
<#macro hasParents>
<#if bo.isChild()>
	<#nested>
</#if>
</#macro>

<#-- is a root Test  -->
<#-- tests if the currnet BO is a root -->
<#macro isRoot>
<#if !bo.isChild()>
	<#nested>
</#if>
</#macro>

<#-- is a Editable Test  -->
<#-- IF 
		Member NOT read only  
	AND 
		Member NOT Hidden 
	THEN
		Member = editable-->
		
<#-- NOTE: THIS IS DEPRECATED!!!! SEE isVisible, isReadOnly, isNotReadOnly INSTEAD -->
<#macro isEditable>
<#if !member.readOnly && !member.hidden>
	<#nested>
</#if>
</#macro>


<#-- is a Target  -->
<#-- tests if the currnet BO is a Target for a given relationship -->
<#macro isTarget entity relation>
<#if util.isTarget(entity, relation)>
	<#nested>
</#if>
</#macro>

<#-- is a Source  -->
<#-- tests if the currnet BO is a Source for a given relationship -->
<#macro isSource entity relation>
<#if util.isSource(entity, relation)>
	<#nested>
</#if>
</#macro>

<#--
Purpose: Checks if the relationship is bidirectional.
Params: A Relationship object
Author: Erik Gustavson
Date: September 1, 2005
-->
<#macro isBidirectional relation>
<#if util.isBidirectional(relation)>
	<#nested>
</#if>
</#macro>


<#-- *************** Loops *************** -->

<#-- Child List Loop  -->
<#-- gets all children that are in the To positions in M:1 and M:M relationships  -->
<#macro SelectBoxListLoop>
<#list util.getSelectBoxLists(bo) as child>
	<#assign child = child>
	<#nested>
</#list>
</#macro>


<#-- Child List Loop  -->
<#-- gets all children that are in the To positions in 1:M and M:M relationships  -->
<#macro childrenListLoop>
<#list util.getAllChildLists(bo) as child>
	<#assign child = child>
	<#nested>
</#list>
</#macro>

<#-- Parent Loop  -->
<#-- Checks to see if an Entity has any Parents -->
<#macro parentLoop>
<#list bo.parentEntities as parent>
	<#assign parent = parent>
	<#nested>
</#list>
</#macro>

<#-- Entity Loop -->
<#macro boLoop>
<#list app.entities as bo>
	<#assign bo = bo>
	<#assign count = 0>
	<#nested count>
	<#assign count = count + 1>
</#list>
</#macro>

<#-- Member Loop -->
<#macro meLoop>
<#assign count = 0>
<#list bo.members as member>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign member = member><#-- neccessary for macros -->
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Validator Loop -->
<#macro vaLoop>
<#assign count = 0>
<#list member.validators as validator>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign validator = validator><#-- neccessary for macros -->
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- multiPartEncode check -->
<#macro multiPartEncode>
<#assign count = 0>
	<#list bo.members as member>
		<#if member.returnType = "com.tps.type.Document" >
			enctype="multipart/form-data"
			<#break>
		</#if>
	</#list>
</#macro>

<#-- Concrete Member Loop: Only members that are concrete members -->
<#macro concreteMemberLoop>
<#assign count = 0>
<#list bo.members as member>
	<#-- IFF Member is "concrete" i.e. a true "Member" object-->
	<#if util.isConcreteMember(member)>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign member = member><#-- neccessary for macros -->
		<#nested count>
		<#assign count = init + 1>
	</#if>
</#list>
</#macro>

<#-- Enum Member Loop: Only members that are EnumMembers -->
<#macro  enumMemberLoop>
<#assign count = 0>
<#list bo.members as member>
	<#-- IFF Member is "enum" -->
	<#if util.isEnumMember(member)>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign member = member><#-- neccessary for macros -->
		<#nested count>
		<#assign count = init + 1>
	</#if>
</#list>
</#macro>

<#-- Alias Member Loop: Only members that are alias virtual members -->
<#macro aliasMemberLoop>
<#assign count = 0>
<#list bo.members as member>
	<#-- IFF Member is "Alias" i.e. a fake "Member" object that points to someone else -->
	<#if util.isAliasMember(member)>
		<#assign init = count><#-- this is to compensate for weirdness in macros-->
		<#assign member = member><#-- neccessary for macros -->
			<#nested count>
			<#assign count = init + 1>
	</#if>
</#list>
</#macro>

<#-- CustomString Member Loop: Only members that are CustomString virtual members -->
<#macro customStringMemberLoop>
<#assign count = 0>
<#list bo.members as member>
	<#-- IFF Member is "CustomString" i.e. a fake "Member" object that points to someone else -->
	<#if util.isCustomStringMember(member)>
		<#assign init = count><#-- this is to compensate for weirdness in macros-->
		<#assign member = member><#-- neccessary for macros -->
			<#nested count>
			<#assign count = init + 1>
	</#if>
</#list>
</#macro>

<#--
BeanPathMemberLoop

Purpose: Loops over an Entity and returns all Members of type BeanPathMember
Params: The entity to examine
Author: Erik Gustavson
Date: October 14th, 2005
-->
<#macro beanPathMemberLoop bizObject>
<#assign count = 0>
<#list bizObject.members as member>
	<#-- IFF Member instanceof "BeanPathMember" -->
	<#if util.isBeanPathMember(member)>
		<#assign init = count><#-- this is to compensate for weirdness in macros-->
		<#assign member = member><#-- neccessary for macros -->
			<#nested count>
			<#assign count = init + 1>
	</#if>
</#list>
</#macro>

<#-- Member Loop - 1:M PARENTS ONLY-->
<#-- gets all Parents that are in the From positions in 1:M relationships  -->
<#macro OTMParentLoop>
<#assign count = 0>
<#list util.getOneToManyParents(bo) as parent>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign parent = parent><#-- neccessary for macros -->
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>


<#-- Member Loop - M:M CHILDREN ONLY-->
<#-- gets all children that are in the To positions in M:M relationships  -->
<#macro MTMChildrenLoop>
<#assign count = 0>
<#list util.getManyToManyChildren(bo) as child>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign child = child><#-- neccessary for macros -->
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Member Loop - M:1 CHILDREN ONLY-->
<#-- gets all children that are in the To positions in M:O relationships  -->
<#macro MTOChildrenLoop>
<#assign count = 0>
<#list util.getManyToOneChildren(bo) as child>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign child = child><#-- neccessary for macros -->
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Member Loop - 1:M CHILDREN ONLY-->
<#-- gets all children that are in the To positions in 1:M relationships  -->
<#macro OTMChildrenLoop>
<#assign count = 0>
<#list util.getOneToManyChildren(bo) as child>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign child = child><#-- neccessary for macros -->
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Relationship Loop - 1:M -->
<#-- gets all Entities that are in 1:M relationships where the BO is the source -->
<#macro OTMRelationshipsLoop>
<#assign count = 0>
<#list util.getOneToManyRelationships(bo) as relation>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign parent = relation.getFromEntity()>
	<#assign child = relation.getToEntity()>
	<#assign relation = relation><#-- neccessary for macros -->	
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Relationship Loop - 1:M -->
<#-- gets all Entities that are in 1:M relationships where the BO is the target -->
<#macro OTMRelationshipsLoopInverse>
<#assign count = 0>
<#list util.getOneToManyRelationshipsInverse(bo) as relation>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign parent = relation.getFromEntity()>
	<#assign relation = relation><#-- neccessary for macros -->	
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Relationship Loop - M:M -->
<#-- gets all Entities that are in M:M relationships  -->
<#macro MTMRelationshipsLoop>
<#assign count = 0>
<#list util.getAllManyToManyRelationships(bo) as relation>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign parent = relation.getFromEntity()>
	<#assign child = relation.getToEntity()>
	<#assign relation = relation><#-- neccessary for macros -->	
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Relationship Loop - M:1-->
<#-- gets all Entities that are in M:1 relationships where the BO is the *SOURCE* entity -->
<#macro MTORelationshipsLoop>
<#assign count = 0>
<#list util.getManyToOneRelationships(bo) as relation>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign parent = relation.getFromEntity()>
	<#assign child = relation.getToEntity()>
	<#assign relation = relation><#-- neccessary for macros -->	
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Relationship Loop - M:1-->
<#-- gets all Entities that are in M:1 relationships where the BO is the *TARGET* entity -->
<#macro MTOInverseRelationshipsLoop>
<#assign count = 0>
<#list util.getManyToOneRelationshipsInverse(bo) as relation>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign parent = relation.getFromEntity()>
	<#assign child = relation.getToEntity()>
	<#assign relation = relation><#-- neccessary for macros -->	
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Relationship Loop - M:1-->
<#-- gets all Entities that are in M:1 relationships where the BO is the *SOURCE* entity -->
<#macro OTORelationshipsLoop>
<#assign count = 0>
<#list util.getOneToOneRelationships(bo) as relation>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign parent = relation.getFromEntity()>
	<#assign child = relation.getToEntity()>
	<#assign relation = relation><#-- neccessary for macros -->	
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Relationship Loop - M:1-->
<#-- gets all Entities that are in M:1 relationships where the BO is the *TARGET* entity -->
<#macro OTOInverseRelationshipsLoop>
<#assign count = 0>
<#list util.getOneToOneRelationshipsInverse(bo) as relation>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign parent = relation.getFromEntity()>
	<#assign child = relation.getToEntity()>
	<#assign relation = relation><#-- neccessary for macros -->	
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Tabs Macros -->
<#macro TabsLoop>
<#assign count = 0>
<#list app.tabs as tab>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign tab = tab><#-- neccessary for macros -->	
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Tabs Macros -->
<#macro TabsEntityRefLoop tab>
<#assign count = 0>
<#list tab.entities as entity>
	<#assign init = count><#-- this is to compensate for weirdness in macros-->
	<#assign entity = entity><#-- neccessary for macros -->	
		<#nested count>
		<#assign count = init + 1>
</#list>
</#macro>

<#-- Abstract Method Loop -->
<#macro abstactMethod entity>
	<#list entity.abstractMethods as method>
		<#assign method = method>
		<#nested>
	</#list>
</#macro>
